home *** CD-ROM | disk | FTP | other *** search
- /*
- HighLevelDNS.c
-
- Implements a higher-level of interface to MacTCP.
-
- 11/28/95 MEC - Created.
- */
-
- #include <HighLevelDNS.h>
-
- #if defined(SYMANTEC_C)||defined(THINK_C)
- #else
- #pragma mark -
- #pragma mark •• DNS Lookup Function ••
- #endif
- // --- DNS Lookup Function ---
-
- static Boolean fStrToAddrDone;
-
- static pascal void myStrToAddrDoneProc(struct hostInfo * hostInfoPtr, char* userDataPtr){
-
- fStrToAddrDone = true;
- }
-
- OSErr DNSLookup(char *hostname,ip_addr *host){
- // convert host name to ip_addr
- struct HostInfo theHost;
- HostInfoUPP hiupp;
- OSErr err = noErr;
-
- fStrToAddrDone = false;
- *host = 0;
-
- hiupp = NewHostInfoProc(myStrToAddrDoneProc);
- err = StrToAddr(hostname,&theHost,hiupp,(char*)0L);
-
- if ((err == -1) || (err == cacheFault)){
- // not done yet...
- EventRecord er;
-
- while (!fStrToAddrDone){
- // give the system some time...
- if (WaitNextEvent(everyEvent,&er,100,(RgnHandle)0)){
- if (er.what==keyDown){
- // check for command-period
- char ch;
-
- ch=er.message&charCodeMask;
-
- if ((er.modifiers&cmdKey) && (ch == '.')){
- // the user wants to cancel this operation...
- DisposeHostInfoProc(hiupp);
- return 128;
- }
- } else {
- SysBeep(5); // notify of the error...
- }
- }
- }
- } else if (err!=noErr){
- // error calling StrToAddr
- DisposeHostInfoProc(hiupp);
- return err;
- }
-
- DisposeHostInfoProc(hiupp);
-
- // ah, the name has been converted, just take it out of the HostInfo record...
- *host = theHost.addr[0];
- return theHost.rtnCode;
- }
-
- OSErr DNSLookupHost(ip_addr host,char* hostname){
- // convert host name to ip_addr
- struct HostInfo theHost;
- HostInfoUPP hiupp;
- OSErr err = noErr;
-
- fStrToAddrDone = false;
- *hostname = 0;
-
- hiupp = NewHostInfoProc(myStrToAddrDoneProc);
- err = AddrToName(host,&theHost,hiupp,(char*)0L);
-
- if ((err == -1) || (err == cacheFault)){
- // not done yet...
- EventRecord er;
-
- while (!fStrToAddrDone){
- // give the system some time...
- if (WaitNextEvent(everyEvent,&er,100,(RgnHandle)0)){
- if (er.what==keyDown){
- // check for command-period
- char ch;
-
- ch=er.message&charCodeMask;
-
- if ((er.modifiers&cmdKey) && (ch == '.')){
- // the user wants to cancel this operation...
- DisposeHostInfoProc(hiupp);
- return 128;
- }
- } else {
- SysBeep(5); // notify of the error...
- }
- }
- }
- } else if (err!=noErr){
- // error calling StrToAddr
- DisposeHostInfoProc(hiupp);
- return err;
- }
-
- DisposeHostInfoProc(hiupp);
-
- // ah, the address has been converted, just take it out of the HostInfo record...
- BlockMoveData((Ptr)theHost.cname,(Ptr)hostname,StrLen(theHost.cname));
- return theHost.rtnCode;
- }
-
-